package com.yanqu.road.dao.impl;

import com.yanqu.road.entity.DataObject;

import java.sql.ResultSet;
import java.sql.SQLException;

public abstract  class TempDataObjectDao<T extends DataObject> extends TempDao {

    public boolean add(T data){
        data.setBeginWriteTime();
        boolean success = addData(data);
        if (success) {
            data.setNoneOption();
        }
        return success;
    }

    public boolean update(T data){
        data.setBeginWriteTime();
        boolean success = updateData(data);
        if (success) {
            data.setNoneOption();
        }
        return success;
    }

    protected T parse(ResultSet rs)throws SQLException {
        T data = parseData(rs);
        if (data != null) {
            data.setNoneOption();
        }
        return data;
    }

    /**
     * 添加
     * @param data 数据对象
     * @return
     */
    protected abstract boolean addData(T data);

    /**
     * 更新单个对象
     * @param data
     * @return
     */
    protected abstract boolean updateData(T data);

    /**
     * 解析单个对象
     * @param rs
     * @return
     */
    protected abstract T parseData(ResultSet rs) throws SQLException;
}
